package day06;

class RunnableDemo implements Runnable {

    private String threadName;

    RunnableDemo(String name) {
        threadName = name;
        System.out.println("Creating " + threadName);
    }

    public void run() {
        System.out.println("Running " + threadName);
        try {
            for (int i = 4; i > 0; i--) {
                System.out.println("Thread: " + threadName + ", " + i);
                // 让线程睡眠一会
                Thread.sleep(50);
            }
        } catch (InterruptedException e) {
            System.out.println("Thread " + threadName + " interrupted.");
        }
        System.out.println("Thread " + threadName + " exiting.");
    }

}

public class ThreadDemo2 {

    public static void main(String args[]) {
        RunnableDemo R1 = new RunnableDemo("Thread-1");
        new Thread(R1).start();

        RunnableDemo R2 = new RunnableDemo("Thread-2");
        new Thread(R2).start();
    }
}